package com.example.wtt.service;


import com.alibaba.fastjson2.JSON;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.wtt.entity.Painting;
import com.example.wtt.mapper.PaintingMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

@Service
public class PaintingService extends ServiceImpl<PaintingMapper, Painting> {
    @Autowired
    private RestTemplate restTemplate;

    @Autowired
    private PaintingMapper paintingMapper;
    @Value("#{'${wtt.text-to-image}'}")
    private String wttUrl;

    public Object paint(Painting painting) {
        String paint_uuid = restTemplate.postForObject(wttUrl, painting, String.class);
        String url = "http://localhost:9090/paint/" + paint_uuid + ".png";
        painting.setUrl(url);
        System.out.println(painting);
        saveOrUpdate(painting);
        return painting;
    }
}
